package com.kjlink.internal.workreport.config;

import cn.xuqiudong.common.base.web.intercept.SaveRequestInterceptor;
import com.kjlink.internal.workreport.system.service.SystemService;
import com.kjlink.internal.workreport.web.AuthenticationIntercepter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * web相关的一些配置
 *
 * @author Vic.xu
 * @since 2024-04-30
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private SystemService systemService;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //1. 权限拦截器
        InterceptorRegistration registration = registry.addInterceptor(new AuthenticationIntercepter(systemService));
        registration.addPathPatterns("/**")
                .excludePathPatterns("/api/**")
                .excludePathPatterns("/v3/**")
                .excludePathPatterns("/test/**")
                .excludePathPatterns("/login").excludePathPatterns("/static/**", "/css/**",
                        "/js/**", "/assets/**");
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(new SaveRequestInterceptor());

        //2. 保存请求地址拦截器
        interceptorRegistration.addPathPatterns("/index/", "/project/", "/report/**", "/jira/", "/group/", "/user/", "/other/day-report-summary", "/stats/")
                .excludePathPatterns("/api/**")
                .excludePathPatterns("/login").excludePathPatterns("/static/**", "/css/**",
                        "/js/**", "/assets/**");
    }
}
